package org.example.springbirthday.service;

import org.example.springbirthday.mapper.NoticeMapper;
import org.example.springbirthday.mapper.UserInfoMapper;
import org.example.springbirthday.model.Notice;
import org.example.springbirthday.model.UserInfo;
import org.example.springbirthday.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 九转苍翎
 * Date: 2025/8/13
 * Time: 21:37
 */
@Service
public class NoticeService {

    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private NoticeMapper noticeMapper;

    public Integer publish(Notice notice, Integer userId) {
        UserInfo userInfo = userInfoMapper.getUserById(userId);
        notice.setUserId(userInfo.getId());
        notice.setUserName(userInfo.getUserName());
        notice.setPublishDateStatus(DateUtils.dateFormat(new Date()));
        return noticeMapper.publish(notice);
    }

    public Notice getNoticeById(Integer id) {
        return noticeMapper.getNoticeById(id);
    }

    public List<Notice> getNoticeList() {
        return noticeMapper.getNoticeList();
    }

    public Integer update(Notice notice) {
        return noticeMapper.update(notice);
    }

    public Integer delete(Integer id) {
        return noticeMapper.delete(id);
    }
}
